package org.tech4j.springboot.starter.edi.schedule.common;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.tech4j.edi.alarm.api.AlarmHandler;
import org.tech4j.edi.api.RetryRecordService;
import org.tech4j.edi.persistence.api.RetryConfigPersistService;
import org.tech4j.edi.persistence.api.RetryRecordPersistService;
import org.tech4j.edi.schedule.common.DefaultScanRetryAlarmService;
import org.tech4j.edi.schedule.common.DefaultScanRetryService;
import org.tech4j.edi.schedule.common.ScanRetryAlarmService;
import org.tech4j.edi.schedule.common.ScanRetryService;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/10 16:22
 **/
@Configuration
public class EdiScheduleCommonConfiguration {
    @Bean
    @ConditionalOnBean(value = {RetryRecordService.class, RetryRecordPersistService.class})
    @ConditionalOnMissingBean(ScanRetryService.class)
    public ScanRetryService scanRetryService(
            final RetryRecordService retryRecordService,
            final RetryRecordPersistService retryRecordPersistService) {
        return new DefaultScanRetryService(retryRecordService, retryRecordPersistService);
    }

    @Bean
    @ConditionalOnBean(value = {AlarmHandler.class, RetryConfigPersistService.class})
    @ConditionalOnMissingBean(ScanRetryAlarmService.class)
    public ScanRetryAlarmService scanRetryAlarmService(
            final AlarmHandler alarmHandler,
            final RetryConfigPersistService retryConfigPersistService) {
        return new DefaultScanRetryAlarmService(alarmHandler, retryConfigPersistService);
    }
}
